export default {
  cookie: {
    set: function (_key, _val, _expirationDay) {
      var d = new Date();
      d.setTime(d.getTime() + (_expirationDay * 24 * 60 * 60 * 1000));
      var expires = "expires=" + d.toUTCString();
      document.cookie = _key + "=" + _val + "; " + expires;
    },
    get: function (_key) {
      var name = _key + "=";
      var ca = document.cookie.split(';');
      for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
          c = c.substring(1);
        }
        if (c.indexOf(name) != -1) {
          return c.substring(name.length, c.length);
        }
      }
      return "";
    },
    remove: function (_key) {
      this.set(_key, '', -1);
    },
  },
  local: {
    set: function (key, val) {
      localStorage.setItem(key, val);
    },
    get: function (key) {
      return localStorage.getItem(key);
    },
    remove: function (key) {
      localStorage.removeItem(key);
    },
    clear: function () {
      localStorage.clear();
    },
    /**
     * 更改 locKey 的本地存储中 key 字段的值为 val
     * @param locKey
     * @param key
     * @param val
     */
    updateAKey: function (locKey, key, val) {
      var locObjStr = localStorage.getItem(locKey) ? localStorage.getItem(locKey) : '';
      var locObj = {};
      if (locObjStr != '' && locObjStr != null && locObjStr != undefined) {
        locObj = JSON.parse(locObjStr);
      }
      locObj[key] = val;
      localStorage.setItem(locKey, JSON.stringify(locObj));
    },
  },
}